﻿using Common.FrontEnd;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Util;
using Util.Props;

namespace FrontEnd
{
    /// <summary>
    /// An abstract DataProcessor implementing elements common to all concrete DataProcessors, such as name, predecessor, and
    /// timer.
    /// </summary>
    public class BaseDataProcessor : ConfigurableAdapter, IDataProcessor
    {
        private IDataProcessor predecessor;
        private Timer timer;

        public BaseDataProcessor() 
        {
        }

        /// <summary>
        /// Returns the processed Data output.
        /// </summary>
        /// <returns>an Data object that has been processed by this DataProcessor</returns>
        virtual public IData getData()
        {
            throw new NotImplementedException("public IData getData()");
        }


        /// <summary>
        /// Initializes this DataProcessor. This is typically called after the DataProcessor has been configured. 
        /// </summary>
        virtual public void initialize() 
        {

        }


        /**
        /// Returns the predecessor DataProcessor.
         *
        /// @return the predecessor
         */
        public IDataProcessor getPredecessor() 
        {
            return predecessor;
        }


        /**
        /// Returns the timer this DataProcessor uses.
         *
        /// @return the timer
         */
        public Timer getTimer() 
        {
            if(timer == null)
                this.timer = TimerPool.getTimer(this, Utilities.getReadable(getName()));
            
            return timer;
        }


        /**
        /// Sets the predecessor DataProcessor. This method allows dynamic reconfiguration of the front end.
         *
        /// @param predecessor the new predecessor of this DataProcessor
         */
        public void setPredecessor(IDataProcessor predecessor) 
        {
            this.predecessor = predecessor;
        }
    }
}
